<template>
	<view>
		<!-- 1，头部组件 -->
		<my-head v-if="isVisitorLogin" :userInfo="userData"></my-head>
		<!-- 1.2，未登录头像 -->
		<my-head-login v-else></my-head-login>
		<!-- 2，我的发布 -->
		<my-release></my-release>
		<!-- 3，常用功能 -->
		<my-list-commonly></my-list-commonly>
	</view>
</template>

<script>
	//1，导入子组件
	import myHead from './my-child/my-head.vue'
	import myRelease from './my-child/my-release.vue'
	import myListCommonly from './my-child/my-list-commonly.vue'
	import myHeadLogin from './my-child/my-head-login.vue'

	//2，导入网络请求
	import {
		getUserInfo
	} from '@/api/http/main/my/user.js'
	
	import {
		mapState,
		mapMutations,
		mapActions
	} from 'vuex'
	
	import websocketMix from '@/mixins/websocket_init.js'

	export default {
		components: {
			myHead,
			myRelease,
			myListCommonly,
			myHeadLogin
		},
		mixins: [websocketMix],
		data() {
			return {
				userId: uni.getStorageSync('userId'),
				userData: {},
				isVisitorLoginData: ''
			}
		},
		computed: {
			...mapState('m_user_info', ['userInfo', 'isVisitorLogin']),
		},
		methods: {
			//1，查询信息
			getUserInfo() {
				getUserInfo(this.userId).then(res => {
					if (res.data.pubInfo.code !== 0) {
						return uni.$showMsg(res.data.pubInfo.message);
					}
					//2.3，参数保存
					this.userData = res.data.busInfo
					//console.log(this.userData)
				})
			},
		},
		onLoad() {
			// if (this.isVisitorLogin) {
			// 	this.getUserInfo()
			// }
		},
		onShow() {
			this.isVisitorLoginData = this.isVisitorLogin
			if (this.isVisitorLogin) {
				this.getUserInfo()
			}
		}
	}
</script>

<style>

</style>